﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameFramework.GameLogic;
using Microsoft.Xna.Framework;
using MyRaceGame.GameLogic.InputControl;
using GameFramework.Controller;
using Microsoft.Xna.Framework.Graphics;

namespace MyRaceGame.GameLogic.GameStates
{
    public abstract class RaceGameState : GameState
    {
        public RaceGameState(RaceGame raceGame)
            : base(raceGame)
        {
            this.raceGame = this.gameStateContext as RaceGame;
        }

        public override void Update(GameTime gameTime)
        {
            UpdateKeyboard(gameTime);
            UpdateRacers(gameTime);
            UpdateTransition(gameTime);
            UpdateAdditional(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            DrawObjects(gameTime);
            DrawRacers(gameTime);
            DrawingAdditional(gameTime);
            DrawText(gameTime);
        }

        protected virtual void UpdateKeyboard(GameTime gameTime)
        {
        }

        protected virtual void UpdateRacers(GameTime gameTime)
        {
        }

        protected virtual void UpdateTransition(GameTime gameTime)
        {
        }

        protected virtual void UpdateAdditional(GameTime gameTime)
        {
        }

        protected virtual void DrawObjects(GameTime gameTime)
        {
        }

        protected virtual void DrawRacers(GameTime gameTime)
        {
        }

        protected virtual void DrawText(GameTime gameTime)
        {
        }

        protected virtual void DrawingAdditional(GameTime gameTime)
        {
        }

        public static void LoadTextureFrom(RaceGame raceGame, ref Texture2D texture, string mainFolder, string name)
        {
            if (texture == null)
                texture = raceGame.Content.Load<Texture2D>(mainFolder + @"\" + name);
        }

        protected GameState GameState
        {
            get { return raceGame.GameState; }
            set { raceGame.GameState = value; }
        }

        protected InputController InputController
        {
            get { return raceGame.InputController; }
            set { raceGame.InputController = value; }
        }

        protected RaceController RaceController
        {
            get { return raceGame.RaceController; }
            set { raceGame.RaceController = value; }
        }

        protected TextDrawController TextDrawController
        {
            get { return raceGame.TextDrawController; }
            set { raceGame.TextDrawController = value; }
        }

        protected RaceGame raceGame;
        protected static RaceGameState instance = null;
    }
}
